package com.yto.cn.map.po;

import java.util.HashMap;
import java.util.Objects;

/**
 * @author dongxing
 **/
public class EqualsTest {

    public static void main(String[] args) {
        Person p1 = new Person(1, "2");
        Person p2 = new Person(1, "5");
        System.out.println(p1.equals(p2));

        HashMap hashMap = new HashMap();
        hashMap.put(p1, "2");
        System.out.println(hashMap.get(p2));


    }
}

class Person {
    private Integer id;
    private String name;

    public Person(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return id == person.id;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }
}
